from dataclasses import dataclass
from src.base import camel_case_filter
import re

@dataclass
class FieldProcessor:
    """字段处理器，处理字段名称的转换等"""
    def to_camel_case(self, name: str) -> str:
        """转换为驼峰命名"""
        return camel_case_filter(name)

    def to_pascal_case(self, name: str) -> str:
        """转换为帕斯卡命名"""
        camel = self.to_camel_case(name)
        return camel[0].upper() + camel[1:] if camel else ''

    def to_kebab_case(self, name: str) -> str:
        """转换为短横线命名"""
        # 1. 处理下划线
        s1 = name.replace('_', '-')
        # 2. 处理驼峰命名
        s2 = re.sub('([A-Z])', r'-\1', s1)
        # 3. 处理连续的短横线
        s3 = re.sub('-+', '-', s2)
        # 4. 处理开头的短横线
        s4 = s3.strip('-')
        # 5. 转换为小写
        return s4.lower()

    def to_snake_case(self, name: str) -> str:
        """转换为下划线命名"""
        # 1. 处理短横线
        s1 = name.replace('-', '_')
        # 2. 处理驼峰命名
        s2 = re.sub('([A-Z])', r'_\1', s1)
        # 3. 处理连续的下划线
        s3 = re.sub('_+', '_', s2)
        # 4. 处理开头的下划线
        s4 = s3.strip('_')
        # 5. 转换为小写
        return s4.lower()